package com.yun.baymax.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.widget.ImageView;

import com.bumptech.glide.request.target.BitmapImageViewTarget;

/**
 * Created by YUN on 2017/6/14.
 */

public class GlideUtils {
    public static BitmapImageViewTarget setCircle(final Context context, final ImageView imageView) {
        BitmapImageViewTarget bitmapImageViewTarget = new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                imageView.setImageDrawable(circularBitmapDrawable);
            }
        };
        return bitmapImageViewTarget;
    }

    public static BitmapImageViewTarget setRadius(final Context context, final ImageView imageView, final float radius) {
        BitmapImageViewTarget bitmapImageViewTarget = new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable bitmapDrawable =
                        RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                bitmapDrawable.setCornerRadius(radius);
                imageView.setImageDrawable(bitmapDrawable);
            }
        };
        return bitmapImageViewTarget;
    }
}
